/**
 * Copyright 2010 Powersi. All rights reserved.
 * 
 */
package com.powersi.sys.manager.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.powersi.hygeia.framework.util.DateFunc;
import com.powersi.hygeia.framework.util.UtilFunc;
import com.powersi.hygeia.web.BaseAction;
import com.powersi.sys.manager.dao.LogDAO;
import com.powersi.sys.util.PagerHelper;
import com.powersi.sys.util.UserKindHelper;

/**
 * The Class QueryLoginLogAction.
 */
public class QueryLoginLogAction extends BaseAction {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** The begin date. */
    String beginDate = null;

    /** The end date. */
    String endDate = null;

    /** The login user. */
    String loginUser = null;

    /** The user name. */
    String userName = null;

    /** The user kind. */
    List userKind = null;

    /** The login flag. */
    String loginFlag = "all";

    /* (non-Javadoc)
     * @see com.opensymphony.xwork2.ActionSupport#execute()
     */
    @Override
    public String execute() throws Exception {

        try {
            if (UtilFunc.isEmpty(beginDate)) {
                java.util.Date now = DateFunc.getDate();
                //beginDate = DateFunc.datetimeToString(DateFunc.addDays(now, -9));
                beginDate = DateFunc.datetimeToString(now);
                endDate = DateFunc.datetimeToString(DateFunc.addDays(now, 1));
            }

            Map<String, String> code = UserKindHelper.valueMap(getUserInfo().getUserKind());
            setAttribute("codeUserKind", code);
            
            Map paramMap = new HashMap();
            paramMap.putAll(getAllParameters());
            if (userKind == null) {
                userKind = new ArrayList<String>();
                userKind.addAll(code.keySet());
                paramMap.put("userKind", UtilFunc.toStringArray(userKind));
            }

            LogDAO dao = (LogDAO) getBean(LogDAO.class);

            PagerHelper.initPagination(getRequest());
            setAttribute("loginfo", PagerHelper.getPaginatedList(dao.queryLoginLog(beginDate, endDate, paramMap)));
            return SUCCESS;
        } catch (Exception ex) {
            saveError(ex);
            return ERROR;
        }

    }

    /**
     * Gets the begin date.
     * 
     * @return the begin date
     */
    public String getBeginDate() {
        return beginDate;
    }

    /**
     * Sets the begin date.
     * 
     * @param beginDate
     *            the new begin date
     */
    public void setBeginDate(String beginDate) {
        this.beginDate = beginDate;
    }

    /**
     * Gets the end date.
     * 
     * @return the end date
     */
    public String getEndDate() {
        return endDate;
    }

    /**
     * Sets the end date.
     * 
     * @param endDate
     *            the new end date
     */
    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    /**
     * Gets the login user.
     * 
     * @return the login user
     */
    public String getLoginUser() {
        return loginUser;
    }

    /**
     * Sets the login user.
     * 
     * @param loginUser
     *            the new login user
     */
    public void setLoginUser(String loginUser) {
        this.loginUser = loginUser;
    }

    /**
     * Gets the user name.
     * 
     * @return the user name
     */
    public String getUserName() {
        return userName;
    }

    /**
     * Sets the user name.
     * 
     * @param userName
     *            the new user name
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * Gets the user kind.
     * 
     * @return the user kind
     */
    public List getUserKind() {
        return userKind;
    }

    /**
     * Sets the user kind.
     * 
     * @param userKind
     *            the new user kind
     */
    public void setUserKind(List userKind) {
        this.userKind = userKind;
    }

    /**
     * Gets the login flag.
     * 
     * @return the login flag
     */
    public String getLoginFlag() {
        return loginFlag;
    }

    /**
     * Sets the login flag.
     * 
     * @param loginFlag
     *            the new login flag
     */
    public void setLoginFlag(String loginFlag) {
        this.loginFlag = loginFlag;
    }
}